package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import static org.jsola.hr.example.EmpSocBackRecordInfoExample.*;

/**
 * 社保回款信息
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class EmpSocBackRecordInfoQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_EMP_SOC_INFO_ID, example = E_EMP_SOC_INFO_ID)
    @Length(max = 32)
    private String empSocInfoId;

    @ApiParam(value = N_EMP_ID, example = E_EMP_ID)
    @Length(max = 32)
    private String empId;

    @ApiParam(value = N_YEAR, example = E_YEAR)
    @Length(max = 32)
    private String year;

    @ApiParam(value = N_MONTH, example = E_MONTH)
    @Length(max = 32)
    private String month;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = "公司Ids 使用','隔开")
    private String companyIds;

    private List<String> companyIdList;

    @ApiParam(value = N_STATUS, example = E_STATUS)
    private Integer status;

    @ApiParam(value = "姓名/手机号/身份证号")
    private String nameOrPhoneOrIdCard;

    @ApiParam(value = "负责人姓名")
    private String empResponsibleName;

    @ApiParam(value = "未回款金额上限")
    private BigDecimal surplusAmountMax;

    @ApiParam(value = "未回款金额下限")
    private BigDecimal surplusAmountMin;

    @ApiParam(value = "回款计划Id列表")
    private List<String> idList;

    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public EmpSocBackRecordInfoQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

